package hn.cch.action;

import com.opensymphony.xwork2.ActionSupport;
import hn.cch.model.Term;
import hn.cch.service.TermService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by chench on 2020-5-21.
 */
@ParentPackage("struts-default")
@Namespace("/term")
@Component
public class TermAction extends ActionSupport {

    private Logger logger = LoggerFactory.getLogger(TermAction.class);

    @Autowired
    private TermService termService;

    @Action(value = "getAll", results = {
            @Result(name = "index", location = "/index.jsp")
    })
    public String getAll(){
        logger.debug("term getAll");

        List<Term> TermList = termService.getAll();
        logger.debug("term list size : " + TermList.size());
        for (Term Term:TermList) {
            logger.debug(Term.toString());
        }

        return "index";
    }
}
